package com.inspsys.algorithms.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.inspsys.common.annotation.Log;
import com.inspsys.common.core.controller.BaseController;
import com.inspsys.common.core.domain.AjaxResult;
import com.inspsys.common.enums.BusinessType;
import com.inspsys.algorithms.domain.AlgorithmsSampleLibrary;
import com.inspsys.algorithms.service.IAlgorithmsSampleLibraryService;
import com.inspsys.common.utils.poi.ExcelUtil;
import com.inspsys.common.core.page.TableDataInfo;

/**
 * sampleLibraryController
 *
 * @author inspsys
 * @date 2025-01-08
 */
@RestController
@RequestMapping("/algorithms/library")
public class AlgorithmsSampleLibraryController extends BaseController
{
    @Autowired
    private IAlgorithmsSampleLibraryService algorithmsSampleLibraryService;

    /**
     * 查询sampleLibrary列表
     */
    @PreAuthorize("@ss.hasPermi('algorithms:library:list')")
    @GetMapping("/list")
    public TableDataInfo list(AlgorithmsSampleLibrary algorithmsSampleLibrary)
    {
        startPage();
        List<AlgorithmsSampleLibrary> list = algorithmsSampleLibraryService.selectAlgorithmsSampleLibraryList(algorithmsSampleLibrary);
        return getDataTable(list);
    }

    /**
     * 导出sampleLibrary列表
     */
    @PreAuthorize("@ss.hasPermi('algorithms:library:export')")
    @Log(title = "sampleLibrary", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AlgorithmsSampleLibrary algorithmsSampleLibrary)
    {
        List<AlgorithmsSampleLibrary> list = algorithmsSampleLibraryService.selectAlgorithmsSampleLibraryList(algorithmsSampleLibrary);
        ExcelUtil<AlgorithmsSampleLibrary> util = new ExcelUtil<AlgorithmsSampleLibrary>(AlgorithmsSampleLibrary.class);
        util.exportExcel(response, list, "sampleLibrary数据");
    }

    /**
     * 获取sampleLibrary详细信息
     */
    @PreAuthorize("@ss.hasPermi('algorithms:library:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(algorithmsSampleLibraryService.selectAlgorithmsSampleLibraryById(id));
    }

    /**
     * 新增sampleLibrary
     */
    @PreAuthorize("@ss.hasPermi('algorithms:library:add')")
    @Log(title = "sampleLibrary", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AlgorithmsSampleLibrary algorithmsSampleLibrary)
    {
        return toAjax(algorithmsSampleLibraryService.insertAlgorithmsSampleLibrary(algorithmsSampleLibrary));
    }

    /**
     * 修改sampleLibrary
     */
    @PreAuthorize("@ss.hasPermi('algorithms:library:edit')")
    @Log(title = "sampleLibrary", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AlgorithmsSampleLibrary algorithmsSampleLibrary)
    {
        return toAjax(algorithmsSampleLibraryService.updateAlgorithmsSampleLibrary(algorithmsSampleLibrary));
    }

    /**
     * 删除sampleLibrary
     */
    @PreAuthorize("@ss.hasPermi('algorithms:library:remove')")
    @Log(title = "sampleLibrary", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(algorithmsSampleLibraryService.deleteAlgorithmsSampleLibraryByIds(ids));
    }
}
